const app = getApp()
Page({
  data: {
    avatar: '',
    nickName: '',
  },
  onLoad() {
    // 获取用户信息
    app.token && this.getUserProfile()
  },
  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  async getUserProfile() {
    // 调用用户信息接口
    await wx.http.get('/userInfo').then((res) => {
      if (res.code !== 10000) return wx.utils.messagePrompt()
      this.setData({
        avatar: res.data.avatar,
        nickName: res.data.nickName,
      })
      app.UserProfile = {
        avatar: res.data.avatar,
        nickName: res.data.nickName,
      }
    })
  },
})
